<template>
  <div id="bigDiv">
    <head-2 />
    <div id="bigTitle">判别时钟小能手</div>
    <div id="countDown">
      倒计时<span id="timeNumber">{{ countDwon }}</span
      >s
    </div>
    <beginView
      :textInfo="this.textInfo"
      @isOpen="getOpen"
      v-if="this.isOpend==1"
    />
    <div id="contentDiv">
      <div class="box">
        <div class="clock" id="ck">
          <div id="hour"></div>
          <div id="min"></div>
          <div id="sec"></div>
        </div>
      </div>
      <div id="anserTitle">钟表上的时间为：</div>
      <div id="anser"><input type="time" value="13:59:59" id="time" step="1"/></div>
      <div id="nextQustion" @click="isPass">下一题</div>
    </div>
    <GetScore :userScore="this.userScore" v-if="this.isOpend==4" @onceTime="getOpenOnce"/>
  </div>
</template>

<script>
import head2 from "@/components/Head/head2.vue";
import BeginView from '@/components/beginView/beginView.vue';
import GetScore from '@/components/getScore/getScore.vue';
export default {
  components: { head2,BeginView, GetScore },
  data() {
    return {
      s:0,
      h:0,
      m:0,
      countDwon: 60,
      isOpend: 1,
      isEnd: false,
      textInfo: {
        val: "游戏开始了，加油小朋友",
        textTitlle: "比一比的玩法介绍",
        textContant:
          "小朋友，每次游戏你都有10秒钟的时间进行游戏，加油！！",
      },
      userScore: {
        score: 0,
        allCount: 14,
        rightCount: 0,
        falseCount: 0,
        rightRate: 0,
        echartId:"compareCount"+new Date()
      },
    };
  },
  mounted() {
    //   this.contDwon()
      this.getClock()
  },
  watch:{
    isOpend(){
      this.contDwon()
    }
  },
  methods: {
    computedRes(){
      this.countDwon=1
      this.isOpend=4
      this.isEnd = !this.isEnd;
    },
    getRes(){
      this.isOpend=4
    },
    getOpen(val) {
      this.isOpend = val;
    },
    getOpenOnce(val){
      this.isOpend = val;
      this.countDwon=10
      this.userScore.allCount=0
      this.userScore.rightCount=0
      this.userScore.falseCount=0
      this.userScore.rightRate=0
    },
    contDwon() {
      const timer = setInterval(() => {
        this.countDwon--;
        if (this.countDwon <= 0) {
          // this.userScore.rightRate=this.userScore.rightCount/this.userScore.allCount
          clearInterval(timer);
          this.isOpend=4
          this.isEnd = !this.isEnd;
          // this.isEnd = !this.isEnd;
        }
      }, 1000);
    },
    
    getClock() {
      var hour = document.getElementById("hour");
      var min = document.getElementById("min");
      var sec = document.getElementById("sec");
      //获取此时的时间
      
     this.s = Math.floor(Math.random()*60)+1;
     this.m = Math.floor(Math.random()*60)+1;
     this.h = Math.floor(Math.random()*12)+1;
      //给指针元素赋值（计算指针旋转度数）
      sec.style.transform = "rotate(" + (this.s * 6 + 270) + "deg)";
      min.style.transform = "rotate(" + (this.m * 6 + 270) + "deg)";
      hour.style.transform = "rotate(" + (this.h * 30 + 270) + "deg)";
      console.log(this.h,this.m,this.s)
    },
    isPass(){
      const newArr=document.getElementById("time").value.split(":")
      console.log(newArr[0],newArr[1],newArr[2])
      if(newArr[0]==this.h&&newArr[1]==this.m&&newArr[2]==this.s){
        this.userScore.rightCount++
      }
      else{
        this.userScore.falseCount++
      }
      this.userScore.allCount=this.userScore.rightCount+this.userScore.falseCount
      this.userScore.rightRate=this.userScore.rightCount/this.userScore.allCount
      document.getElementById("time").value=""
      this.getClock()
    }
  },
};
</script>

<style lang="less" scoped>
#bigDiv {
  height: 100vh;
  #nextQustion{
    font-size: 19px;
    font-weight: bold;
    margin-top: 5vh;
    letter-spacing: 2px;
  }
  #anserTitle{
    z-index: 5;
    position: relative;
    margin-top: 20vh;
    font-weight: bold;
    letter-spacing: 1px;
    font-size: 20px;
  }
  #anser{ 
    position: relative;
    margin-top: 5vh;
    z-index: 5;
    font-size: 22px;
    input{
      padding: 1vw;
      border: none;
      width: 36vw;
      height: 5vh;
      font-size: 22px;
      color: black;
      background-color: rgb(121, 204, 237);
    }
  }
  .box {
    height: 40vw;
    width: 40vw;
    margin: 0 auto;
    position: relative;
    margin-left: 5vw;
    margin-top: -5vh;
    transform: scale(0.4);
  }
  //表盘
  .clock {
    width: 800px;
    height: 800px;
    background: url("@/assets/biao.png") no-repeat center;
    background-position: -858px -2400px;
    zoom: 69%;
  }

  //时针
  #hour {
    position: absolute;
    top: 610px;
    left: 600px;
    width: 204px;
    height: 17px;
    background: url("@/assets/biao.png") no-repeat center;
    border: 1px gray solid;
    background-position: -1848px -1031px;
    zoom: 69%;
  }
  //分针
  #min {
    position: absolute;
    top: 610px;
    left: 600px;
    width: 302px;
    height: 15px;
    background: url("@/assets/biao.png") no-repeat center;
    border: 1px gray solid;
    background-position: -1848px -1109px;
    zoom: 69%;
  }
  //秒针
  #sec {
    position: absolute;
    top: 616px;
    left: 600px;
    width: 336px;
    height: 6px;
    background: url("@/assets/biao.png") no-repeat center;
    border: 1px rgb(255, 0, 0) solid;
    background-position: -1848px -1191px;
    zoom: 69%;
  }
  //设置三个指针的旋转中心移动左边
  #hour,
  #min,
  #sec {
    transform-origin: left;
  }
  #countDown {
    font-size: 18px;
    font-weight: bold;
    margin-top: 30px;
    letter-spacing: 2px;
    #timeNumber {
      color: red;
    }
  }
  #bigTitle {
    font-weight: bold;
    font-size: 22px;
    margin-top: 20px;
    letter-spacing: 3px;
  }
  #contentDiv {
    // height: 40vh;
    // display: flex;
    // justify-content: space-around;
    // align-items: center;
  }
}
</style>